/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package share;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import javax.swing.JLabel;
import javax.swing.Timer;

/**
 *
 * @author mire
 */
public class TimerLabel extends JLabel {

    public TimerLabel() {
        this.setText("00:00:00");
        this.timerFormat = new SimpleDateFormat("HH:mm:ss");
        this.time = Calendar.getInstance();
        time.set(Calendar.YEAR, Calendar.MONTH, Calendar.DATE, 0, 0, 0);
        setTimer();
    }

    public void start() {
        t.start();
    }

    private void setTimer() {
        t = new javax.swing.Timer(1000, new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                time.add(Calendar.SECOND, 1);
                setText(timerFormat.format(time.getTime()));
                repaint();
            }
        });

    }
    private Timer t;
    private SimpleDateFormat timerFormat;
    private Calendar time;
}
